package com.stryker.complaint;

import java.util.List;

import com.stryker.R;
import com.stryker.model.Project;
import com.stryker.model.User;
import com.stryker.network.CallService;
import com.stryker.newproject.ListViewNewProjectsAdapter;
import com.stryker.newproject.ScreenNewProjectActivity;
import com.stryker.ultilities.Application;
import com.stryker.ultilities.Ultilities;

import android.app.Activity;
import android.app.Dialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ListView;

public class ScreenComplaint extends Activity {
	
	/** The Constant SOAP_ACTION. */
	private static final String SOAP_ACTION = "http://tempuri.org/M_GetProject";

	/** The Constant METHOD_NAME. */
	private static final String METHOD_NAME = "M_GetProject";

	/** The Constant NAMESPACE. */
	private static final String NAMESPACE = "http://tempuri.org/";

	private List<Project> listProjects;
	private List<Project> listProjectsSearch;
	private Application apps;
	private User user;
	private String minIndex = "0";
	private String maxIndex = "30";
	private String _where = ""; // set search

	private LinearLayout linearLayoutNodata;

	private EditText txt_search_project;
	private ListViewNewProjectsAdapter m_Adapter;
	private ListView listViewProject;

	private Dialog progressDialog;
	
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
				WindowManager.LayoutParams.FLAG_FULLSCREEN);
		Ultilities.mLockScreenRotation(this);
		setContentView(R.layout.screen_complaint_project);
		
		linearLayoutNodata = (LinearLayout) findViewById(R.id.linearLayoutNodata);
		txt_search_project = (EditText) findViewById(R.id.txt_search_project);

		listViewProject = (ListView) findViewById(R.id.listViewProject);
		progressDialog = Ultilities.showProgressDialog(this);
		progressDialog.show();
		
		apps = (Application) getApplication();
		user = apps.getUser();
		
		String[] params = new String[] { user.getUserType(), "7", minIndex,
				maxIndex, _where, user.getUserID() };

		new GetDataFromWebService().execute(params);
	}
	private class GetDataFromWebService extends AsyncTask<String, Void, String> {

		@Override
		protected String doInBackground(String... urls) {
			// TODO Auto-generated method stub
			
			String URL = getResources().getString(R.string.Config_Url_Server);
			CallService callService = new CallService();

			listProjects = callService.getAllNewProjects(SOAP_ACTION,
					METHOD_NAME, NAMESPACE, URL, urls[0], urls[1], urls[2],
					urls[3], urls[4], urls[5]);
			return null;
		}
		@Override
		protected void onPostExecute(String result) {
			if (listProjects.size() > 0) {
				m_Adapter = new ListViewNewProjectsAdapter(
						ScreenComplaint.this,
						R.layout.row_new_project, listProjects);
				listViewProject.setAdapter(m_Adapter);
			} else {
				linearLayoutNodata.setVisibility(View.VISIBLE);
			}
			progressDialog.cancel();
		}
		
	}
}

